package www.com.springboot_20200312;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import www.com.springboot_20200312.rabbitmqDemo.Demo07Message.producer.Demo07Producer;
import www.com.springboot_20200312.rabbitmqDemo.batchSendMessage.producer.DemoBatchProducer;

import java.util.concurrent.CountDownLatch;

/**
 * @program: springboot_20200312
 * @ClassName DemoBatchProducerTest
 * @description:
 * @author: jht
 * @create: 2021-12-07 14:27
 * @Version 1.0
 **/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = JhtWorkStudy.class)
public class DemoProducerTest07 {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private Demo07Producer producer;

    /** @Author jht
     * @Description //消费重试
     * @Date 14:28 2021/12/7 0007
     * @Param
     * @return
     **/
    @Test
    public void testSyncSend() throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            // 同步发送消息
            int id = (int) (System.currentTimeMillis() / 1000);
            producer.syncSend(id);

            // 故意每条消息之间，隔离 10 秒
            logger.info("[testSyncSend][发送编号：[{}] 发送成功]", id);
            Thread.sleep(10 * 1000L);
        }

        // 阻塞等待，保证消费
        new CountDownLatch(1).await();
    }
}
